/**
    入驻小区
**/
(function (vc) {
    var DEFAULT_PAGE = 1;
    var DEFAULT_ROWS = 10;
    vc.extends({
        data: {
            communityRecommendInfo: {
                recommends: [],
                total: 0,
                records: 1,
                moreCondition: false,
                crId: '',
                communityName:'',
                conditions: {
                    communityId: '',
                    recommendType: '',
                    prodName: '',
                }
            }
        },
        _initMethod: function () {
            vc.emit('adminCommunity', 'initCommunity',function(_community){
                $that.communityRecommendInfo.conditions.communityId = _community.communityId;
                $that.communityRecommendInfo.communityName = _community.name;
                $that._listCommunityRecommends(DEFAULT_PAGE, DEFAULT_ROWS);
            });
            $that._listCommunityRecommends(DEFAULT_PAGE, DEFAULT_ROWS);
        },
        _initEvent: function () {

            vc.on('communityRecommend', 'listCommunityRecommend', function (_param) {
                $that._listCommunityRecommends(DEFAULT_PAGE, DEFAULT_ROWS);
            });
            vc.on('pagination', 'page_event', function (_currentPage) {
                $that._listCommunityRecommends(_currentPage, DEFAULT_ROWS);
            });
        },
        methods: {
            _listCommunityRecommends: function (_page, _rows) {

                $that.communityRecommendInfo.conditions.page = _page;
                $that.communityRecommendInfo.conditions.row = _rows;
                let param = {
                    params: $that.communityRecommendInfo.conditions
                };

                //发送get请求
                vc.http.apiGet('/recommend.listCommunityRecommend',
                    param,
                    function (json, res) {
                        let _json = JSON.parse(json);
                        $that.communityRecommendInfo.total = _json.total;
                        $that.communityRecommendInfo.records = _json.records;
                        $that.communityRecommendInfo.recommends = _json.data;
                        vc.emit('pagination', 'init', {
                            total: $that.communityRecommendInfo.records,
                            currentPage: _page
                        });
                    }, function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            _openAddShopRecommend:function(){
                vc.emit('addShopRecommend', 'openAddShopRecommendModal',{
                    communityId:$that.communityRecommendInfo.conditions.communityId,
                    communityName:$that.communityRecommendInfo.communityName,
                });
            },
            _openAddServRecommend:function(){
                vc.emit('addServRecommend', 'openAddServRecommendModal',{
                    communityId:$that.communityRecommendInfo.conditions.communityId,
                    communityName:$that.communityRecommendInfo.communityName,
                });
            },
            _openAddCommunityRecommendModal: function () {
                vc.emit('addCommunityRecommend', 'openAddCommunityRecommendModal', {
                    communityId:$that.communityRecommendInfo.conditions.communityId,
                    communityName:$that.communityRecommendInfo.communityName,
                });
            },
            _openEditCommunityRecommendModel: function (_communityRecommend) {
                vc.emit('editCommunityRecommend', 'openEditCommunityRecommendModal', _communityRecommend);
            },
            _openDeleteCommunityRecommendModel: function (_communityRecommend) {
                vc.emit('deleteCommunityRecommend', 'openDeleteCommunityRecommendModal', _communityRecommend);
            },
            _queryCommunityRecommendMethod: function () {
                $that._listCommunityRecommends(DEFAULT_PAGE, DEFAULT_ROWS);

            },
            _moreCondition: function () {
                if ($that.communityRecommendInfo.moreCondition) {
                    $that.communityRecommendInfo.moreCondition = false;
                } else {
                    $that.communityRecommendInfo.moreCondition = true;
                }
            }


        }
    });
})(window.vc);
